﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using FDEE.Model;
using FDEEInterface;
using FDEEPublicFunc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FDEEDrawingModels
{
    public class PlotRCPlatTable
    {
        static string _dwgPath = "";//构造物
        static string _blcName = "MI12";

     
        #region 等宽现浇板
        /// <summary>
        /// 等宽现浇板
        /// </summary>
        /// <param name="db"></param>
        /// <param name="eType"></param>
        /// <param name="listRebar"></param>
        /// <param name="dwgPath"></param>
        /// <param name="typeName"></param>
        /// <param name="structureName"></param>
        /// <param name="type"></param>
        /// <param name="eConType"></param>
        /// <param name="conValue"></param>
        /// <param name="scale"></param>
        public static void DrawingDeckSlabTable(Database db, MemberBase ret, string dwgPath,
            string pierName, FDEE.Model.eSubType type, int scale = 1, string title = "MAINLINE", string tkPath = "", bool isDEck = true)
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("数据异常");
            }
            _dwgPath = dwgPath;
            Extents2d ext = new Extents2d(Point2d.Origin, Point2d.Origin);
            Point2d CT = Point2d.Origin;
            Point2d M1 = CT.Convert2D(0, -2 * scale);

            #region 绘制表格
            Table lasTb = new Table();

            ext = new Extents2d(Point2d.Origin.Convert2D(), Point2d.Origin);
            lasTb = DrawTable(db, ref ext, M1.Convert3D(), ret.RebarList.Count + 2,
                Extensions.curFont, scale, ret.RebarList, pierName, type, title, 0);
            Extents2d extMerge = new Extents2d();


            // 绘制合并表格
            RebarCollection listBack = new RebarCollection();
            listBack = ret.RebarList;
            List<string> mergeList = new List<string>();
            mergeList.Add("Materials");
            mergeList.Add("Materials");
            mergeList.Add("Unit");
            mergeList.Add("Weight(kg)");
            mergeList.Add("Total(kg)");

            Point3d pt = M1.Convert3D(0, -lasTb.Height - 10 * scale);
            Table tb = DrawMergeTable(db, ret, ref extMerge, pt, mergeList,
                Extensions.curFont, scale);
            double width = 0;
            double height = 0;
            if (tb != null)
            {
                width = tb.Width;
                height = tb.Height;

                string str1 = string.Format("REINFORCEMENT QUANTITIES OF DECK SLAB FOR {0} OF {1}", pierName, title);
                string str2 = "";
                TextPloter.PrintScaleDoubleSideText(db, pt.Convert2D(width / 2, 4 * scale), 3, str1, str2, ref extMerge, scale, Extensions.curFont);
            }
            if (isDEck)
                Common.CreateLayoutNew(db, "T梁现浇板", ext, extMerge, scale, 1, 0, 0, false, tkPath);
            else
                Common.CreateLayoutNew(db, "T梁现浇板", ext, extMerge, scale, 1, 0, 0, false, tkPath);


            #endregion
        }

        public static Table DrawTable(Database db, ref Extents2d ext, Point3d startPoint,
int rowNum, string txtStyle, double scale, RebarCollection tbValue,
string pierName, FDEE.Model.eSubType type, string title = "MAINLINE", int pageCount = 0)
        {
            //表格表头
            List<string> headName = new List<string>();
            headName.Add("Bar\\PMark");
            headName.Add("Reinf.\\PType");
            headName.Add("Sharp Configuration");
            headName.Add("Typical\\PFormula");
            headName.Add("R\\P(mm)");
            headName.Add("d\\P(mm)");
            headName.Add("r\\P(mm)");
            headName.Add("h\\P(mm)");
            headName.Add("n\\P(mm)");
            headName.Add("Lx\\P(mm)");
            headName.Add("A\\P(mm)");
            headName.Add("B\\P(mm)");
            headName.Add("C\\P(mm)");
            headName.Add("D\\P(mm)");
            headName.Add("Quantity\\P(No./Ea.)");
            headName.Add("Length\\P(m./Ea.)");
            headName.Add("Total Length\\P(m)");
            headName.Add("Unit Weight\\P(kg/m)");
            headName.Add("Total Weight\\P(kg)");

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                //int rowNum = tbValue.Count + 2;
                // 创建table 
                startPoint = startPoint.Convert3D(420 * pageCount);
                Table tb = new Table();
                int colNum = headName.Count;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                #region 第一页
                #region 第一行 标题
                tb.Cells[0, 0].TextString = String.Format("TABLE OF REINFORCEMENT BAR LIST OF DECK SLAB FOR {0} OF {1} ", pierName, title);
                tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                tb.ScaleFactors = new Scale3d(1);
                tb.Cells[0, 0].Contents[0].TextStyleId = id;
                #endregion
                tb.Rows[0].Height = 9 * scale;

                #region 第二行 表格标题
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, i].Contents[0].Rotation = 0;
                    tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, i].Contents[0].TextStyleId = id;
                }
                #endregion

                tb.Rows[1].Height = 16 * scale;

                #region 设置表格值
                if (tbValue.Count > 0)
                {
                    for (int m = 0; m < tbValue.Count; m++)
                    {
                        try
                        {
                            //
                            string value = "";
                            int n = 0;
                            value = tbValue[m].MBarMark.ToString();
                            if (tbValue[m].SBarMark != 0)
                                value = tbValue[m].MBarMark.ToString() + "." + tbValue[m].SBarMark.ToString() + tbValue[m].CBarMark;
                            else
                                value = tbValue[m].MBarMark.ToString() + tbValue[m].CBarMark;
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            n++;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Diameter.ToString(); //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //Formula
                            n = n + 2;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Formula == null ? "-" : tbValue[m].Formula; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //R
                            n++;
                            value = "";
                            if (tbValue[m].R != 0)
                                value = tbValue[m].R.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //d
                            n++;
                            value = "";
                            if (tbValue[m].Diameter != 0)
                            {
                                value = System.Text.RegularExpressions.Regex.Replace(tbValue[m].Diameter.ToString(), @"[^0-9]+", "");
                            }
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //r
                            n++;
                            value = "";
                            if (tbValue[m].r != 0)
                                value = tbValue[m].r.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //h
                            n++;
                            value = "";
                            if (tbValue[m].h != 0)
                                value = tbValue[m].h.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //n
                            n++;
                            value = "";
                            if (tbValue[m].n != 0)
                                value = tbValue[m].n.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Lx
                            n++;
                            value = "";
                            if (tbValue[m].Lx != 0)
                                value = tbValue[m].Lx.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //A
                            n++;
                            value = "";
                            if (tbValue[m].A != 0)
                                value = tbValue[m].A.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //B
                            n++;
                            value = "";
                            if (tbValue[m].B != 0)
                                value = tbValue[m].B.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //C
                            n++;
                            value = "";
                            if (tbValue[m].C != 0)
                                value = tbValue[m].C.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //D
                            n++;
                            value = "";
                            if (tbValue[m].D != 0)
                                value = tbValue[m].D.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Quantity
                            n++;
                            value = "";
                            if (tbValue[m].Quantity != 0)
                                value = tbValue[m].Quantity.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Length
                            n++;
                            value = "";
                            if (tbValue[m].Length != 0)
                                value = tbValue[m].Length.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = double.Parse(value).ToString("0.000"); //获取i行j列数据
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalLength
                            n++;
                            value = "";
                            if (tbValue[m].TotalLength != 0)
                                value = tbValue[m].TotalLength.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = double.Parse(value).ToString("0.000")/*string.Format("{0:N3}", double.Parse(value))*/;
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //UnitWeight
                            n++;
                            value = "";
                            if (tbValue[m].UnitWeight != 0)
                                value = tbValue[m].UnitWeight.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = double.Parse(value).ToString("0.000")/* string.Format("{0:N3}", double.Parse(value))*/;
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalWeight
                            n++;
                            value = "";
                            if (tbValue[m].TotalWeight != 0)
                                value = tbValue[m].TotalWeight.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = double.Parse(value).ToString("0.000") /*string.Format("{0:N3}", double.Parse(value))*/;
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            if (tbValue[m].ShapeConfg.ToString().Contains("MABC"))
                                _blcName = "MABC";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MAB"))
                                _blcName = "MAB";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MBA"))
                                _blcName = "MBA";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MA"))
                                _blcName = "MA";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MWAVE"))
                                _blcName = "MWAVE";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MO"))
                                _blcName = "MO";
                            db.CopyBlockFromFile(_dwgPath, _blcName);

                            BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 16 * m + 8)), 0.8, _blcName, _dwgPath, 0);

                        }
                        catch (Exception ex)
                        { }
                    }
                }

                #endregion

                #region 表格添加数据

                #endregion

                #region 设置列宽
                // 设置列宽
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0)
                        tb.Columns[i].Width = 4 * 3 * scale;
                    else if (i == 1)
                        tb.Columns[i].Width = 5 * 3 * scale;
                    else if (i == 2)
                        tb.Columns[i].Width = 16 * 3 * scale;
                    else if (i == 3)
                        tb.Columns[i].Width = 11 * 3 * scale;
                    else if (i > headName.Count - 4)
                        tb.Columns[i].Width = 9 * 3 * scale;
                    else if (i > headName.Count - 6)
                        tb.Columns[i].Width = 8 * 3 * scale;
                    else
                        tb.Columns[i].Width = 4 * 3 * scale;
                }
                #endregion

                //行高
                for (int i = 2; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 16 * scale;
                }

                #region 列单元格合并


                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                #endregion

                #region 其他页

                #endregion
                tr.Commit();
                return tb;
            }
        }
        #endregion

        #region I梁三角区
        public static void DrawingSDeckSlabTable(Database db, MemberBase ret, string dwgPath,
           string pierName, string type,  int scale = 1, string title = "MAINLINE", string tkPath = "", int pageno = 0)
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("数据异常");
            }
            _dwgPath = dwgPath;
            Extents2d ext = new Extents2d(Point2d.Origin.Convert2D(0, -297 * pageno), Point2d.Origin.Convert2D(0, -297 * pageno));
            Point2d CT = Point2d.Origin;
            Point2d M1 = CT.Convert2D(0, -2 * scale).Convert2D(0, -297 * pageno);

            #region 绘制表格
            Table lasTb = new Table();

            ext = new Extents2d(Point2d.Origin.Convert2D(0, -297 * pageno), Point2d.Origin.Convert2D(0, -297 * pageno));
            lasTb = DrawSDeckTable(db, ref ext, M1.Convert3D(), ret.RebarList.Count + 2,
                Extensions.curFont, scale, ret.RebarList, pierName, type, title, 0);
            Extents2d extMerge = new Extents2d();


            // 绘制合并表格
            RebarCollection listBack = new RebarCollection();
            listBack = ret.RebarList;
            List<string> mergeList = new List<string>();
            mergeList.Add("Materials");
            mergeList.Add("Materials");
            mergeList.Add("Unit");
            mergeList.Add("Weight(kg)");
            mergeList.Add("Total(kg)");

            Point3d pt = M1.Convert3D(0, -lasTb.Height - 40 * scale);
            Table tb = DrawMergeTable(db, ret, ref extMerge, pt, mergeList,
                Extensions.curFont, scale,false);
            double width = 0;
            double height = 0;
            if (tb != null)
            {
                width = tb.Width;
                height = tb.Height; 

                string str1 = string.Format("REINFORCEMENT QUANTITIES OF ONE SKEW BRIDGE DECK OF TYPE {0}", type);
                string str2 = "";
                TextPloter.PrintScaleDoubleSideText(db, pt.Convert2D(width / 2, 4 * scale), 3, str1, str2, ref extMerge, scale, Extensions.curFont);
            }         
            Common.CreateLayoutNew(db, "I梁三角区", ext, extMerge, scale, 1, pageno, 0, false, tkPath);


            #endregion
        }

        public static Table DrawSDeckTable(Database db, ref Extents2d ext, Point3d startPoint,
int rowNum, string txtStyle, double scale, RebarCollection tbValue,
string pierName, string type, string title = "MAINLINE", int pageCount = 0)
        {
            //表格表头
            List<string> headName = new List<string>();
            headName.Add("Bar\\PMark");
            headName.Add("Reinf.\\PType");
            headName.Add("Sharp Configuration");
            headName.Add("Typical\\PFormula");
            headName.Add("R\\P(mm)");
            headName.Add("d\\P(mm)");
            headName.Add("r\\P(mm)");
            headName.Add("h\\P(mm)");
            headName.Add("n\\P(mm)");
            headName.Add("Lx\\P(mm)");
            headName.Add("A\\P(mm)");
            headName.Add("B\\P(mm)");
            headName.Add("C\\P(mm)");
            headName.Add("D\\P(mm)");
            headName.Add("Quantity\\P(No./Ea.)");
            headName.Add("Length\\P(m./Ea.)");
            headName.Add("Total Length\\P(m)");
            headName.Add("Unit Weight\\P(kg/m)");
            headName.Add("Total Weight\\P(kg)");

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                //int rowNum = tbValue.Count + 2;
                // 创建table 
                startPoint = startPoint.Convert3D(420 * pageCount);
                Table tb = new Table();
                int colNum = headName.Count;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                #region 第一页
                #region 第一行 标题
                tb.Cells[0, 0].TextString = String.Format("TABLE OF REINFORCEMENT BAR LIST OF ONE SKEW BRIDGE DECK OF TYPE {0} ", type);
                tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                tb.ScaleFactors = new Scale3d(1);
                tb.Cells[0, 0].Contents[0].TextStyleId = id;
                #endregion
                tb.Rows[0].Height = 9 * scale;

                #region 第二行 表格标题
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, i].Contents[0].Rotation = 0;
                    tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, i].Contents[0].TextStyleId = id;
                }
                #endregion

                tb.Rows[1].Height = 14.5 * scale;

                #region 设置表格值
                if (tbValue.Count > 0)
                {
                    for (int m = 0; m < tbValue.Count; m++)
                    {
                        try
                        {
                            //
                            string value = "";
                            int n = 0;
                            value = tbValue[m].MBarMark.ToString();
                            if (tbValue[m].SBarMark != 0)
                                value = tbValue[m].MBarMark.ToString() + "." + tbValue[m].SBarMark.ToString() + tbValue[m].CBarMark;
                            else
                                value = tbValue[m].MBarMark.ToString() + tbValue[m].CBarMark;
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            n++;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Diameter.ToString(); //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //Formula
                            n = n + 2;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Formula == null ? "-" : tbValue[m].Formula; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //R
                            n++;
                            value = "";
                            if (tbValue[m].R != 0)
                                value = tbValue[m].R.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //d
                            n++;
                            value = "";
                            if (tbValue[m].Diameter != 0)
                            {
                                value = System.Text.RegularExpressions.Regex.Replace(tbValue[m].Diameter.ToString(), @"[^0-9]+", "");
                            }
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //r
                            n++;
                            value = "";
                            if (tbValue[m].r != 0)
                                value = tbValue[m].r.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //h
                            n++;
                            value = "";
                            if (tbValue[m].h != 0)
                                value = tbValue[m].h.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //n
                            n++;
                            value = "";
                            if (tbValue[m].n != 0)
                                value = tbValue[m].n.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Lx
                            n++;
                            value = "";
                            if (tbValue[m].Lx != 0)
                                value = tbValue[m].Lx.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //A
                            n++;
                            value = "";
                            if (tbValue[m].A != 0)
                                value = tbValue[m].A.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //B
                            n++;
                            value = "";
                            if (tbValue[m].B != 0)
                                value = tbValue[m].B.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //C
                            n++;
                            value = "";
                            if (tbValue[m].C != 0)
                                value = tbValue[m].C.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //D
                            n++;
                            value = "";
                            if (tbValue[m].D != 0)
                                value = tbValue[m].D.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Quantity
                            n++;
                            value = "";
                            if (tbValue[m].Quantity != 0)
                                value = tbValue[m].Quantity.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Length
                            n++;
                            value = "";
                            if (tbValue[m].Length != 0)
                                value = tbValue[m].Length.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = double.Parse(value).ToString("0.000"); //获取i行j列数据
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalLength
                            n++;
                            value = "";
                            if (tbValue[m].TotalLength != 0)
                                value = tbValue[m].TotalLength.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = double.Parse(value).ToString("0.000")/*string.Format("{0:N3}", double.Parse(value))*/;
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //UnitWeight
                            n++;
                            value = "";
                            if (tbValue[m].UnitWeight != 0)
                                value = tbValue[m].UnitWeight.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = double.Parse(value).ToString("0.000")/* string.Format("{0:N3}", double.Parse(value))*/;
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalWeight
                            n++;
                            value = "";
                            if (tbValue[m].TotalWeight != 0)
                                value = tbValue[m].TotalWeight.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = double.Parse(value).ToString("0.000") /*string.Format("{0:N3}", double.Parse(value))*/;
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            if (tbValue[m].ShapeConfg.ToString().Contains("MABC"))
                                _blcName = "MABC";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("M2ABCD"))
                                _blcName = "M2ABCD";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MAB"))
                                _blcName = "MAB";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MBA"))
                                _blcName = "MBA";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MA"))
                                _blcName = "MA";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MWAVE"))
                                _blcName = "MWAVE";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MO"))
                                _blcName = "MO";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MSZ"))
                                _blcName = "MSZ";
                            db.CopyBlockFromFile(_dwgPath, _blcName);

                            BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 14.5 * scale + 13 * m + 7)), 0.8, _blcName, _dwgPath, 0);

                        }
                        catch (Exception ex)
                        { }
                    }
                }

                #endregion

                #region 表格添加数据

                #endregion

                #region 设置列宽
                // 设置列宽
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0)
                        tb.Columns[i].Width = 4 * 3 * scale;
                    else if (i == 1)
                        tb.Columns[i].Width = 5 * 3 * scale;
                    else if (i == 2)
                        tb.Columns[i].Width = 16 * 3 * scale;
                    else if (i == 3)
                        tb.Columns[i].Width = 11 * 3 * scale;
                    else if (i > headName.Count - 4)
                        tb.Columns[i].Width = 9 * 3 * scale;
                    else if (i > headName.Count - 6)
                        tb.Columns[i].Width = 8 * 3 * scale;
                    else
                        tb.Columns[i].Width = 4 * 3 * scale;
                }
                #endregion

                //行高
                for (int i = 2; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 13 * scale;
                }

                #region 列单元格合并


                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                #endregion

                #region 其他页

                #endregion
                tr.Commit();
                return tb;
            }
        }
        #endregion

        #region 预制板
        public static void DrawingRCPlatTable(Database db, MemberBase ret, string dwgPath,
           string pierName, FDEE.Model.eSubType type, int typenum, int L, int scale = 1, string title = "MAINLINE", string tkPath = "",int pageno=0)
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("数据异常");
            }
            _dwgPath = dwgPath;
            Extents2d ext = new Extents2d(Point2d.Origin.Convert2D(0,-297* pageno), Point2d.Origin.Convert2D(0, -297 * pageno));
            Point2d CT = Point2d.Origin;
            Point2d M1 = CT.Convert2D(0, -2 * scale).Convert2D(0, -297 * pageno);

            #region 绘制表格
            Table lasTb = new Table();

            ext = new Extents2d(Point2d.Origin.Convert2D(0, -297 * pageno), Point2d.Origin.Convert2D(0, -297 * pageno));
            lasTb = DrawRCPlatTable(db, ref ext, M1.Convert3D(), ret.RebarList.Count + 2,
                Extensions.curFont, scale, ret.RebarList, pierName, type, typenum, L, title, 0);
            Extents2d extMerge = new Extents2d();


            // 绘制合并表格
            RebarCollection listBack = new RebarCollection();
            listBack = ret.RebarList;
            List<string> mergeList = new List<string>();
            mergeList.Add("Materials");
            mergeList.Add("Materials");
            mergeList.Add("Unit");
            mergeList.Add("Weight(kg)");
            mergeList.Add("Total(kg)");

            Point3d pt = M1.Convert3D(0, -lasTb.Height - 40 * scale);
            extMerge = new Extents2d(pt.Convert2D(), pt.Convert2D());
            Table tb = DrawMergeTable(db, ret, ref extMerge, pt, mergeList,
                Extensions.curFont, scale);
            double width = 0;
            double height = 0;
            if (tb != null)
            {
                width = tb.Width;
                height = tb.Height;

                string str1 = string.Format("REINFORCEMENT QUANTITIES OF ONE PRECAST RC DECK PANELS OF TYPE {0}-{1} (L={2}M)", type.ToString(), typenum, (L * 0.001).ToString("0.000"));
                string str2 = "";
                TextPloter.PrintScaleDoubleSideText(db, pt.Convert2D(width / 2, 4 * scale), 3, str1, str2, ref extMerge, scale, Extensions.curFont);
            }
            Common.CreateLayoutNew(db, "预制板钢筋", ext, extMerge, scale, 1, pageno, 0, false, tkPath);


            #endregion
        }

        public static Table DrawRCPlatTable(Database db, ref Extents2d ext, Point3d startPoint,
int rowNum, string txtStyle, double scale, RebarCollection tbValue,
string pierName, FDEE.Model.eSubType type, int typenum, int L, string title = "MAINLINE", int pageCount = 0)
        {
            //表格表头
            List<string> headName = new List<string>();
            headName.Add("Bar\\PMark");
            headName.Add("Reinf.\\PType");
            headName.Add("Sharp Configuration");
            headName.Add("Typical\\PFormula");
            headName.Add("R\\P(mm)");
            headName.Add("d\\P(mm)");
            headName.Add("r\\P(mm)");
            headName.Add("h\\P(mm)");
            headName.Add("n\\P(mm)");
            headName.Add("Lx\\P(mm)");
            headName.Add("A\\P(mm)");
            headName.Add("B\\P(mm)");
            headName.Add("C\\P(mm)");
            headName.Add("D\\P(mm)");
            headName.Add("Quantity\\P(No./Ea.)");
            headName.Add("Length\\P(m./Ea.)");
            headName.Add("Total Length\\P(m)");
            headName.Add("Unit Weight\\P(kg/m)");
            headName.Add("Total Weight\\P(kg)");

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                //int rowNum = tbValue.Count + 2;
                // 创建table 
                startPoint = startPoint.Convert3D(420 * pageCount);
                Table tb = new Table();
                int colNum = headName.Count;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                #region 第一页
                #region 第一行 标题
                tb.Cells[0, 0].TextString = String.Format("TABLE OF REINFORCEMENT BAR LIST OF ONE PRECAST RC DECK PANELS OF TYPE {0}-{1} (L={2}M)", type.ToString(), typenum, (L * 0.001).ToString("0.000"));
                tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                tb.ScaleFactors = new Scale3d(1);
                tb.Cells[0, 0].Contents[0].TextStyleId = id;
                #endregion
                tb.Rows[0].Height = 9 * scale;

                #region 第二行 表格标题
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, i].Contents[0].Rotation = 0;
                    tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, i].Contents[0].TextStyleId = id;
                }
                #endregion

                tb.Rows[1].Height = 16 * scale;

                #region 设置表格值
                if (tbValue.Count > 0)
                {
                    for (int m = 0; m < tbValue.Count; m++)
                    {
                        try
                        {
                            //
                            string value = "";
                            int n = 0;
                            value = tbValue[m].MBarMark.ToString();
                            if (tbValue[m].SBarMark != 0)
                                value = tbValue[m].MBarMark.ToString() + "." + tbValue[m].SBarMark.ToString() + tbValue[m].CBarMark;
                            else
                                value = tbValue[m].MBarMark.ToString() + tbValue[m].CBarMark;
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            n++;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Diameter.ToString(); //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //Formula
                            n = n + 2;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Formula == null ? "-" : tbValue[m].Formula; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //R
                            n++;
                            value = "";
                            if (tbValue[m].R != 0)
                                value = tbValue[m].R.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //d
                            n++;
                            value = "";
                            if (tbValue[m].Diameter != 0)
                            {
                                value = System.Text.RegularExpressions.Regex.Replace(tbValue[m].Diameter.ToString(), @"[^0-9]+", "");
                            }
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //r
                            n++;
                            value = "";
                            if (tbValue[m].r != 0)
                                value = tbValue[m].r.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //h
                            n++;
                            value = "";
                            if (tbValue[m].h != 0)
                                value = tbValue[m].h.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //n
                            n++;
                            value = "";
                            if (tbValue[m].n != 0)
                                value = tbValue[m].n.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Lx
                            n++;
                            value = "";
                            if (tbValue[m].Lx != 0)
                                value = tbValue[m].Lx.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //A
                            n++;
                            value = "";
                            if (tbValue[m].A != 0)
                                value = tbValue[m].A.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //B
                            n++;
                            value = "";
                            if (tbValue[m].B != 0)
                                value = tbValue[m].B.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //C
                            n++;
                            value = "";
                            if (tbValue[m].C != 0)
                                value = tbValue[m].C.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //D
                            n++;
                            value = "";
                            if (tbValue[m].D != 0)
                                value = tbValue[m].D.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Quantity
                            n++;
                            value = "";
                            if (tbValue[m].Quantity != 0)
                                value = tbValue[m].Quantity.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Length
                            n++;
                            value = "";
                            if (tbValue[m].Length != 0)
                                value = tbValue[m].Length.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = double.Parse(value).ToString("0.000"); //获取i行j列数据
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalLength
                            n++;
                            value = "";
                            if (tbValue[m].TotalLength != 0)
                                value = tbValue[m].TotalLength.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = double.Parse(value).ToString("0.000")/*string.Format("{0:N3}", double.Parse(value))*/;
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //UnitWeight
                            n++;
                            value = "";
                            if (tbValue[m].UnitWeight != 0)
                                value = tbValue[m].UnitWeight.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = double.Parse(value).ToString("0.000")/* string.Format("{0:N3}", double.Parse(value))*/;
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalWeight
                            n++;
                            value = "";
                            if (tbValue[m].TotalWeight != 0)
                                value = tbValue[m].TotalWeight.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = double.Parse(value).ToString("0.000") /*string.Format("{0:N3}", double.Parse(value))*/;
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            if (tbValue[m].ShapeConfg.ToString().Contains("MABC"))
                                _blcName = "MABC";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("M2ABCD"))
                                _blcName = "M2ABCD";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MAB"))
                                _blcName = "MAB";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MBA"))
                                _blcName = "MBA";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MA"))
                                _blcName = "MA";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MWAVE"))
                                _blcName = "MWAVE";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MO"))
                                _blcName = "MO";
                            db.CopyBlockFromFile(_dwgPath, _blcName);

                            BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 16 * m + 8)), 0.8, _blcName, _dwgPath, 0);

                        }
                        catch (Exception ex)
                        { }
                    }
                }

                #endregion

                #region 表格添加数据

                #endregion

                #region 设置列宽
                // 设置列宽
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0)
                        tb.Columns[i].Width = 4 * 3 * scale;
                    else if (i == 1)
                        tb.Columns[i].Width = 5 * 3 * scale;
                    else if (i == 2)
                        tb.Columns[i].Width = 16 * 3 * scale;
                    else if (i == 3)
                        tb.Columns[i].Width = 11 * 3 * scale;
                    else if (i > headName.Count - 4)
                        tb.Columns[i].Width = 9 * 3 * scale;
                    else if (i > headName.Count - 6)
                        tb.Columns[i].Width = 8 * 3 * scale;
                    else
                        tb.Columns[i].Width = 4 * 3 * scale;
                }
                #endregion

                //行高
                for (int i = 2; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 16 * scale;
                }

                #region 列单元格合并


                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                #endregion

                #region 其他页

                #endregion
                tr.Commit();
                return tb;
            }
        }
        #endregion

        #region I梁现浇板-圆弧段
        public static void DrawingTDeckSlabCurveTable(Database db, MemberBase ret,  string dwgPath,
         string pierName, ref int pageCount, int pageNo = 0, int scale = 1, string title = "MAINLINE", string tkPath = "")
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("数据异常");
            }
            _dwgPath = dwgPath;

            Extents2d ext = new Extents2d(Point2d.Origin, Point2d.Origin);
            Point2d CT = Point2d.Origin.Convert2D(0, -297 * pageNo);
            Point2d M1 = CT.Convert2D(0, -2 * scale);

            #region 分页处理
            List<RebarCollection> divDic = new List<RebarCollection>();

            CalcTDeckSlabCurvePage(ret.RebarList,  ref divDic);
      
            #endregion
            pageCount = divDic.Count;
            #region 绘制表格
            Table lasTb = new Table();
            for (int i = 0; i < divDic.Count; i++)
            {
                ext = new Extents2d(Point2d.Origin.Convert2D(420 * i).Convert2D(0, -297 * pageNo), Point2d.Origin.Convert2D(0, -297 * pageNo));
                lasTb = DrawTDeckSlabCurveTable(db, ref ext, M1.Convert3D(), divDic[i].Count + 2,
                    Extensions.curFont, scale, divDic[i],   pierName,  i, title);
                Extents2d extMerge = new Extents2d();
             
                if (i == divDic.Count - 1)
                {
                    // 绘制合并表格
                    RebarCollection listBack = new RebarCollection();
                    listBack = ret.RebarList;
                    List<string> mergeList = new List<string>();
                    mergeList.Add("Materials");
                    mergeList.Add("Materials");
                    mergeList.Add("Unit");
                    mergeList.Add("Weight(kg)");
                    mergeList.Add("Total(kg)");

                    Point3d pt = M1.Convert3D(420 * i + (lasTb.Width - 226) * 0.5, /*-20*/-lasTb.Height - 40 * scale);
                    Table tb = DrawMergeTable(db, ret, ref extMerge, pt, mergeList,
                        Extensions.curFont, scale);
                    double width = 0;
                    double height = 0;
                    if (tb != null)
                    {
                        width = tb.Width;
                        height = tb.Height;

                        string str1 = string.Format("REINFORCEMENT QUANTITIES OF DECK SLAB FOR {0} OF {1}", pierName, title);

                        TextPloter.PrintScaleDoubleSideText(db, pt.Convert2D(width / 2, 8 * scale), 3, str1, "", ref extMerge, scale, Extensions.curFont);
                    }

                    Common.CreateLayoutNew(db, "I梁现浇板-圆弧段", ext, extMerge, scale, 1, pageNo, i, false, tkPath);
                }
                else
                    Common.CreateLayoutNew(db, "I梁现浇板-圆弧段", ext, scale, 1, pageNo, i, false, tkPath);
            }
            #endregion
        }

        public static Table DrawTDeckSlabCurveTable(Database db, ref Extents2d ext, Point3d startPoint,
int rowNum, string txtStyle, double scale, RebarCollection tbValue,  string pierName, int pageCount = 0, string title = "MAINLINE")
        {
            //    //表格表头
            //    List<string> headName = new List<string>();
            //    headName.Add("Bar\\PMark");
            //    headName.Add("Reinf.\\PType");
            //    headName.Add("Sharp Configuration");
            //    headName.Add("Typical\\PFormula");
            //    headName.Add("R\\P(mm)");
            //    headName.Add("d\\P(mm)");
            //    headName.Add("r\\P(mm)");
            //    headName.Add("h\\P(mm)");
            //    headName.Add("n\\P(mm)");
            //    headName.Add("Lx\\P(mm)");
            //    headName.Add("A\\P(mm)");
            //    headName.Add("B\\P(mm)");
            //    headName.Add("C\\P(mm)");
            //    headName.Add("D\\P(mm)");
            //    headName.Add("E\\P(mm)");
            //    headName.Add("Quantity\\P(No./Ea.)");
            //    headName.Add("Length\\P(m./Ea.)");
            //    headName.Add("Total Length\\P(m)");
            //    headName.Add("Unit Weight\\P(kg/m)");
            //    headName.Add("Total Weight\\P(kg)");


            //    using (Transaction tr = db.TransactionManager.StartTransaction())
            //    {
            //        BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
            //        BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
            //            OpenMode.ForWrite) as BlockTableRecord;

            //        ObjectId id;
            //        TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
            //        id = st[txtStyle];

            //        startPoint = startPoint.Convert3D(420 * pageCount);
            Table tb = new Table();
            //        int colNum = headName.Count;
            //        tb.SetSize(rowNum, colNum);       // 设置几行几列
            //        tb.Position = startPoint;
            //        tb.GenerateLayout();
            //        #region 第一页
            //        #region 第一行 标题

            //        tb.Cells[0, 0].TextString = String.Format("TABLE OF REINFORCEMENT BAR LIST OF DECK SLAB FOR {0} OF {1}",
            //                pierName, title);                
            //        tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
            //        tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
            //        tb.Cells[0, 0].Contents[0].Rotation = 0;
            //        //tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
            //        tb.Cells[0, 0].Contents[0].TextStyleId = id;
            //        #endregion
            //        tb.Rows[0].Height = 9 * scale;

            //        #region 第二行 表格标题
            //        for (int i = 0; i < colNum; ++i)
            //        {
            //            tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
            //            tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
            //            tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
            //            tb.Cells[1, i].Contents[0].Rotation = 0;
            //            tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
            //            tb.Cells[1, i].Contents[0].TextStyleId = id;
            //        }
            //        #endregion

            //        tb.Rows[1].Height = 16 * scale;

            //        #region 设置表格值
            //        if (tbValue.Count > 0)
            //        {
            //            for (int m = 0; m < tbValue.Count; m++)
            //            {
            //                try
            //                {
            //                    //
            //                    string value = "";
            //                    int n = 0;
            //                    value = tbValue[m].MBarMark.ToString();

            //                    if (tbValue[m].SBarMark != 0)
            //                        value = tbValue[m].MBarMark.ToString() + "." + tbValue[m].SBarMark.ToString() + tbValue[m].CBarMark;
            //                    else
            //                        value = tbValue[m].MBarMark.ToString() + tbValue[m].CBarMark;

            //                    tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
            //                    tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                    tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                    tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                    tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

            //                    n++;
            //                    tb.Cells[m + 2, n].TextString = tbValue[m].Diameter.ToString(); //获取i行j列数据
            //                    tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                    tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                    tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                    tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

            //                    //Formula
            //                    n = n + 2;
            //                    tb.Cells[m + 2, n].TextString = tbValue[m].Formula == null ? "-" : tbValue[m].Formula; //获取i行j列数据
            //                    tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                    tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                    tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                    tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

            //                    //R
            //                    n++;
            //                    value = "";
            //                    if (tbValue[m].R != 0)
            //                        value = tbValue[m].R.ToString();
            //                    if (tbValue[m].EXNumberList.exNumber["R"] != 0)
            //                    {
            //                        int mid = tbValue[m].R;
            //                        int span = (int)(tbValue[m].EXNumberList.exNumber["R"] * 0.5);
            //                        value = ((mid - span) + "~" + (mid + span) + "*").ToString();
            //                    }
            //                    tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
            //                    if (!string.IsNullOrWhiteSpace(value))
            //                    {
            //                        tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                        tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                        tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                        tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
            //                    }

            //                    //d
            //                    n++;
            //                    value = "";
            //                    if (tbValue[m].Diameter != 0)
            //                    {
            //                        value = System.Text.RegularExpressions.Regex.Replace(tbValue[m].Diameter.ToString(), @"[^0-9]+", "");
            //                    }
            //                    tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
            //                    if (!string.IsNullOrWhiteSpace(value))
            //                    {
            //                        tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                        tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                        tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                        tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
            //                    }

            //                    //r
            //                    n++;
            //                    value = "";
            //                    if (tbValue[m].r != 0)
            //                        value = tbValue[m].r.ToString();
            //                    tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
            //                    if (!string.IsNullOrWhiteSpace(value))
            //                    {
            //                        tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                        tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                        tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                        tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
            //                    }

            //                    //h
            //                    n++;
            //                    value = "";
            //                    if (tbValue[m].h != 0)
            //                        value = tbValue[m].h.ToString();
            //                    tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
            //                    if (!string.IsNullOrWhiteSpace(value))
            //                    {
            //                        tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                        tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                        tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                        tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
            //                    }

            //                    //n
            //                    n++;
            //                    value = "";
            //                    if (tbValue[m].n != 0)
            //                        value = tbValue[m].n.ToString();
            //                    tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
            //                    if (!string.IsNullOrWhiteSpace(value))
            //                    {
            //                        tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                        tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                        tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                        tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
            //                    }

            //                    //Lx
            //                    n++;
            //                    value = "";
            //                    if (tbValue[m].Lx != 0)
            //                        value = tbValue[m].Lx.ToString();
            //                    tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
            //                    if (!string.IsNullOrWhiteSpace(value))
            //                    {
            //                        tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                        tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                        tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                        tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
            //                    }

            //                    //A
            //                    n++;
            //                    value = "";
            //                    if (tbValue[m].A != 0)
            //                        value = tbValue[m].A.ToString();
            //                    if (tbValue[m].EXNumberList.exNumber["A"] != 0)
            //                    {
            //                        int mid = tbValue[m].A;
            //                        int span = (int)(tbValue[m].EXNumberList.exNumber["A"] * 0.5);
            //                        value = ((mid - span) + "~" + (mid + span) + "*").ToString();
            //                    }
            //                    tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
            //                    if (!string.IsNullOrWhiteSpace(value))
            //                    {
            //                        tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                        tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                        tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                        tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
            //                    }

            //                    //B
            //                    n++;
            //                    value = "";
            //                    if (tbValue[m].B != 0)
            //                        value = tbValue[m].B.ToString();
            //                    if (tbValue[m].EXNumberList.exNumber["B"] != 0)
            //                    {
            //                        int mid = tbValue[m].B;
            //                        int span = (int)(tbValue[m].EXNumberList.exNumber["B"] * 0.5);
            //                        value = ((mid - span) + "~" + (mid + span) + "*").ToString();
            //                    }
            //                    tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
            //                    if (!string.IsNullOrWhiteSpace(value))
            //                    {
            //                        tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                        tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                        tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                        tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
            //                    }

            //                    //C
            //                    n++;
            //                    value = "";
            //                    if (tbValue[m].C != 0)
            //                        value = tbValue[m].C.ToString();
            //                    if (tbValue[m].EXNumberList.exNumber["C"] != 0)
            //                    {
            //                        int mid = tbValue[m].C;
            //                        int span = (int)(tbValue[m].EXNumberList.exNumber["C"] * 0.5);
            //                        value = ((mid - span) + "~" + (mid + span) + "*").ToString();
            //                    }
            //                    tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
            //                    if (!string.IsNullOrWhiteSpace(value))
            //                    {
            //                        tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                        tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                        tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                        tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
            //                    }

            //                    //D
            //                    n++;
            //                    value = "";
            //                    if (tbValue[m].D != 0)
            //                        value = tbValue[m].D.ToString();
            //                    if (tbValue[m].EXNumberList.exNumber["D"] != 0)
            //                    {
            //                        int mid = tbValue[m].D;
            //                        int span = (int)(tbValue[m].EXNumberList.exNumber["D"] * 0.5);
            //                        value = ((mid - span) + "~" + (mid + span) + "*").ToString();
            //                    }
            //                    tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
            //                    if (!string.IsNullOrWhiteSpace(value))
            //                    {
            //                        tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                        tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                        tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                        tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
            //                    }
            //                    //E
            //                    n++;
            //                    value = "";
            //                    if (tbValue[m].E != 0)
            //                        value = tbValue[m].E.ToString();
            //                    if (tbValue[m].EXNumberList.exNumber["E"] != 0)
            //                    {
            //                        int mid = tbValue[m].E;
            //                        int span = (int)(tbValue[m].EXNumberList.exNumber["E"] * 0.5);
            //                        value = ((mid - span) + "~" + (mid + span) + "*").ToString();
            //                    }
            //                    tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
            //                    if (!string.IsNullOrWhiteSpace(value))
            //                    {
            //                        tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                        tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                        tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                        tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
            //                    }
            //                    //Quantity
            //                    n++;
            //                    value = "";
            //                    if (tbValue[m].Quantity != 0)
            //                        value = tbValue[m].Quantity.ToString();
            //                    tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
            //                    if (!string.IsNullOrWhiteSpace(value))
            //                    {
            //                        tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                        tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                        tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                        tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
            //                    }

            //                    //Length
            //                    n++;
            //                    value = "";
            //                    if (tbValue[m].Length != 0)
            //                        value = tbValue[m].Length.ToString("0.000").Trim();

            //                    if (!string.IsNullOrWhiteSpace(value))
            //                    {
            //                        tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value)); //获取i行j列数据
            //                        tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                        tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                        tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                        tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
            //                    }

            //                    //TotalLength
            //                    n++;
            //                    value = "";
            //                    if (tbValue[m].TotalLength != 0)
            //                        value = tbValue[m].TotalLength.ToString("0.000").Trim();

            //                    if (!string.IsNullOrWhiteSpace(value))
            //                    {
            //                        tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
            //                        tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                        tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                        tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                        tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
            //                    }

            //                    //UnitWeight
            //                    n++;
            //                    value = "";
            //                    if (tbValue[m].UnitWeight != 0)
            //                        value = tbValue[m].UnitWeight.ToString("0.000").Trim();

            //                    if (!string.IsNullOrWhiteSpace(value))
            //                    {
            //                        tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
            //                        tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                        tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                        tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                        tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
            //                    }

            //                    //TotalWeight
            //                    n++;
            //                    value = "";
            //                    if (tbValue[m].TotalWeight != 0)
            //                        value = tbValue[m].TotalWeight.ToString("0.000").Trim();

            //                    if (!string.IsNullOrWhiteSpace(value))
            //                    {
            //                        tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
            //                        tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
            //                        tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
            //                        tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
            //                        tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
            //                    }

            //                    if (tbValue[m].ShapeConfg.ToString().Contains("MABR"))
            //                        _blcName = "MABCR";
            //                    else if (tbValue[m].ShapeConfg.ToString().Contains("MABC"))
            //                        _blcName = "MABC";
            //                    else if (tbValue[m].ShapeConfg.ToString().Contains("MABR"))
            //                        _blcName = "MABR";
            //                    else if (tbValue[m].ShapeConfg.ToString().Contains("MAB"))
            //                        _blcName = "MAB";
            //                    else if (tbValue[m].ShapeConfg.ToString().Contains("MBAR"))
            //                        _blcName = "MBAR";
            //                    else if (tbValue[m].ShapeConfg.ToString().Contains("MBA"))
            //                        _blcName = "MBA";
            //                    else if (tbValue[m].ShapeConfg.ToString().Contains("MAR"))
            //                        _blcName = "MAR";
            //                    else if (tbValue[m].ShapeConfg.ToString().Contains("MAU"))
            //                        _blcName = "MAU";
            //                    else if (tbValue[m].ShapeConfg.ToString().Contains("MA"))
            //                        _blcName = "MA";
            //                    else if (tbValue[m].ShapeConfg.ToString().Contains("MWAVE"))
            //                        _blcName = "MWAVE";
            //                    else if (tbValue[m].ShapeConfg.ToString().Contains("MO"))
            //                        _blcName = "MO";
            //                    else if (tbValue[m].ShapeConfg.ToString().Contains("MSZ"))
            //                        _blcName = "MSZ";
            //                    else if (tbValue[m].ShapeConfg.ToString().Contains("MUN"))
            //                        _blcName = "MUN";
            //                    else if (tbValue[m].ShapeConfg.ToString().Contains("MUL"))
            //                        _blcName = "MUL";
            //                    else if (tbValue[m].ShapeConfg.ToString().Contains("MUA"))
            //                        _blcName = "MUA";
            //                    else if (tbValue[m].ShapeConfg.ToString().Contains("MLL"))
            //                        _blcName = "MLL";
            //                    db.CopyBlockFromFile(_dwgPath, _blcName);

            //                    BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 20 * scale, -(9 * scale + 16 * scale + 16 * m + 8)), 1, _blcName, _dwgPath, 0);

            //                }
            //                catch (Exception ex)
            //                { }
            //            }
            //        }

            //        #endregion

            //        #region 表格添加数据

            //        #endregion

            //        #region 设置列宽
            //        // 设置列宽
            //        for (int i = 0; i < colNum; ++i)
            //        {
            //            if (i == 0)
            //                tb.Columns[i].Width = 4 * 3 * scale;
            //            else if (i == 1)
            //                tb.Columns[i].Width = 5 * 3 * scale;
            //            else if (i == 2)
            //                tb.Columns[i].Width = 40 * scale;
            //            else if (i == 3)
            //                tb.Columns[i].Width = 25 * scale;
            //            else if (i == 4)
            //                tb.Columns[i].Width = 25 * scale;
            //            else if (i <7)
            //                tb.Columns[i].Width = 15 * scale;
            //            else if (i > headName.Count - 4)
            //                tb.Columns[i].Width = 21 * scale;
            //            else if (i > headName.Count - 6)
            //                tb.Columns[i].Width = 18 * scale;
            //            else
            //                tb.Columns[i].Width = 17 * scale;
            //        }
            //        #endregion

            //        //行高
            //        for (int i = 2; i < rowNum; ++i)
            //        {
            //            tb.Rows[i].Height = 16 * scale;
            //        }


            //        tb.Layer = "细线";
            //        tb.LineWeight = LineWeight.LineWeight013;
            //        tb.ColorIndex = 4;
            //        modelSpace.AppendEntity(tb);
            //        tr.AddNewlyCreatedDBObject(tb, true);
            //        ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

            //        #region  边框粗线设置
            //        List<Point2d> pList = new List<Point2d>();
            //        Point2d pt1 = startPoint.Convert2D();
            //        pList.Add(pt1);
            //        Point2d pt2 = pt1.Convert2D(0, -tb.Height);
            //        pList.Add(pt2);
            //        Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
            //        pList.Add(pt3);
            //        Point2d pt4 = pt1.Convert2D(tb.Width, 0);
            //        pList.Add(pt4);
            //        PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
            //        #endregion

            //        #endregion

            //        #region 其他页
            //        string Contents = "Notes:\\P" +
            //"1. * indicates linear variable, increment equal to △C divides by number of\\P" +
            //"rebar and value varies depend on location of overhang deck slab in will adjust by field. \\P" ;
            //        TextPloter.PrintMultiText(db, ref ext, startPoint.Convert3D(20, -tb.Height), Contents, 1, 2.5, 133);

            //        #endregion
            //        tr.Commit();
            return tb;
            //}
        }



        public static void CalcTDeckSlabCurvePage(RebarCollection listRebar, ref List<RebarCollection> divDic)
        {
            RebarCollection div = new RebarCollection();
            int no = 0;
            for (int i = 0; i < listRebar.Count; ++i)
            {
                //同样的直径和类型合并
                if (i < 13 * (no + 1))
                    div.Add(listRebar[i]);
                else
                {
                    divDic.Add(div);
                    div = new RebarCollection();
                    div.Add(listRebar[i]);
                    no++;
                }
            }
            if (div.Count > 0)
                divDic.Add(div);
        }
        #endregion 

        #region 汇总
        /// <summary>
        /// 汇总表
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ret"></param>
        /// <param name="type"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="headName"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        public static Table DrawMergeTable(Database db, MemberBase ret, ref Extents2d ext,
        Point3d startPoint, List<string> headName, string txtStyle, double scale,bool isCon=true)
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("数据异常");
            }
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                Table tb = new Table();

                Dictionary<eDB, List<RebarBase>> dic = new Dictionary<eDB, List<RebarBase>>();      // 统计合并项

                #region 统计合并数据
                foreach (RebarBase item in ret.RebarList)
                {
                    //if (item.MBarMark < 6)
                    //{
                        if (dic.Count == 0)
                        {
                            List<RebarBase> items = new List<RebarBase>();
                            items.Add(item);
                            dic[item.Diameter] = items;
                        }
                        else
                        {
                            List<RebarBase> items = new List<RebarBase>();
                            dic.TryGetValue(item.Diameter, out items);
                            if (items == null || items.Count == 0)
                            {
                                items = new List<RebarBase>();
                            }
                            items.Add(item);
                            dic[item.Diameter] = items;
                        }
                    //}
                }
                #endregion

                #region 设置表格长宽
                //bool isLoadOther = false;
                int row = dic.Count + 2;
                if(!isCon)
                    row = dic.Count + 1;
                int col = 5;

                tb.SetSize(row, col);
                tb.Position = startPoint;
                tb.GenerateLayout();
                #endregion

                #region 设置表头
                for (int i = 0; i < col; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i];
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                }
                #endregion

                #region 设置表格值
                // 第一行第一列
                tb.Cells[1, 0].TextString = "Bars";
                tb.Cells[1, 0].Contents[0].TextHeight = 2 * scale;
                tb.Cells[1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 0].Contents[0].Rotation = 0;
                tb.Cells[1, 0].Contents[0].TextStyleId = id;

                if (isCon)
                {
                    // 第一列最后一行
                    tb.Cells[dic.Count + 1, 0].TextString = "Concrete";
                    tb.Cells[dic.Count + 1, 0].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[dic.Count + 1, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[dic.Count + 1, 0].Contents[0].Rotation = 0;
                    tb.Cells[dic.Count + 1, 0].Contents[0].TextStyleId = id;
                }

                // 其他数据
                #region Bars, Concreate数据
                double totalWeight = 0;
                for (int i = 1; i < row; ++i)
                {
                    if (i == dic.Count + 1)
                    {
                        if (isCon)
                        {
                            tb.Cells[i, 1].TextString = string.Format("f'c={0}MPa", ret.ConcreteClass.ToString().Replace("C", ""));
                            tb.Cells[i, 1].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[i, 1].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[i, 1].Contents[0].Rotation = 0;
                            tb.Cells[i, 1].Contents[0].TextStyleId = id;

                            tb.Cells[i, 2].TextString = "m3";
                            tb.Cells[i, 2].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[i, 2].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[i, 2].Contents[0].Rotation = 0;
                            tb.Cells[i, 2].Contents[0].TextStyleId = id;

                            tb.Cells[i, 3].TextString = ret.ConcreteVolumn.ToString("0.000")/*string.Format("{0:N3}", ret.ConcreteVolumn)*/;
                            tb.Cells[i, 3].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[i, 3].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[i, 3].Contents[0].Rotation = 0;
                            tb.Cells[i, 3].Contents[0].TextStyleId = id;
                        }
                    }
                    else
                    {
                        KeyValuePair<eDB, List<RebarBase>> pr = new KeyValuePair<eDB, List<RebarBase>>();
                        if (dic.Count > i - 1)
                        {
                            pr = dic.ElementAt(i - 1);
                        }
                        if (pr.Value == null)
                        {
                            continue;
                        }

                        // 类型
                        tb.Cells[i, 1].TextString = pr.Key.ToString();
                        tb.Cells[i, 1].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 1].Contents[0].Rotation = 0;
                        tb.Cells[i, 1].Contents[0].TextStyleId = id;

                        // 单位
                        tb.Cells[i, 2].TextString = "kg";
                        tb.Cells[i, 2].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 2].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 2].Contents[0].Rotation = 0;
                        tb.Cells[i, 2].Contents[0].TextStyleId = id;

                        // 数量
                        double weight = 0;
                        foreach (RebarBase info in pr.Value)
                        {
                            weight += info.TotalWeight;
                        }

                        tb.Cells[i, 3].TextString = weight.ToString("0.000")/* string.Format("{0:N3}", weight)*/;
                        tb.Cells[i, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 3].Contents[0].Rotation = 0;
                        tb.Cells[i, 3].Contents[0].TextStyleId = id;

                        // 总数
                        totalWeight += weight;
                    }

                    // 总数
                    tb.Cells[1, 4].TextString = totalWeight.ToString("0.000")/*string.Format("{0:N3}", totalWeight)*/;
                    tb.Cells[1, 4].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[1, 4].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, 4].Contents[0].Rotation = 0;
                    tb.Cells[1, 4].Contents[0].TextStyleId = id;
                }
                #endregion

                #endregion

                #region 设置行高、列宽
                for (int i = 0; i < col; ++i)
                {
                    if (i == 0)
                    {
                        tb.Columns[i].Width = 30 * scale;
                    }
                    else if (i == 1)
                    {
                        tb.Columns[i].Width = 50 * scale;
                    }
                    else if (i == 2)
                    {
                        tb.Columns[i].Width = 30 * scale;
                    }
                    else if (i == 3)
                    {
                        tb.Columns[i].Width = 40 * scale;
                    }
                    else if (i == 4)
                    {
                        tb.Columns[i].Width = 40 * scale;
                    }
                }

                for (int i = 0; i < row; ++i)
                {
                    tb.Rows[i].Height = 8 * scale;
                }
                #endregion

                #region 合并单元格
                List<CellRange> cellList = new List<CellRange>();

                CellRange range1 = CellRange.Create(tb, 1, 0, dic.Count, 0);
                cellList.Add(range1);

                CellRange range2 = CellRange.Create(tb, 1, 2, dic.Count, 2);
                cellList.Add(range2);

                CellRange range3 = CellRange.Create(tb, 1, 4, dic.Count, 4);
                cellList.Add(range3);

                if (isCon)
                {
                    CellRange range4 = CellRange.Create(tb, dic.Count + 1, 3, dic.Count + 1, 4);
                    cellList.Add(range4);
                }

                CellRange range5 = CellRange.Create(tb, 0, 0, 0, 1);
                cellList.Add(range5);

              

                foreach (CellRange range in cellList)
                {
                    tb.MergeCells(range);
                }
                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                tr.Commit();
                Extents3d ex3d = new Extents3d(tb.Bounds.Value.MinPoint.Convert3D(), tb.Bounds.Value.MaxPoint.Convert3D());
                ext = ex3d.Convert2D();
                return tb;
            }
        }

        public static void DrawListMergeTable(Database db, MemberBase ret, 
Point3d startPoint, string txtStyle, double scale, FDEE.Model.eSubType type, int typenum, int L,int totalNum, string title = "MAINLINE", int num = 2)
        {
            Extents2d ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
           Table tb = new Table();

            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("数据异常");
            }

            Dictionary<eDB, List<RebarBase>> dic = new Dictionary<eDB, List<RebarBase>>();      // 统计合并项

            #region 统计合并数据
            foreach (RebarBase item in ret.RebarList)
            {
               
                    if (dic.Count == 0)
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                    else
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        dic.TryGetValue(item.Diameter, out items);
                        if (items == null || items.Count == 0)
                        {
                            items = new List<RebarBase>();
                        }
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                
            }
            #endregion




            //#region 设置表格长宽

            int row = 3 +dic.Count ;

            int col = 7;

            tb.SetSize(row, col);
            tb.Position = startPoint;
            tb.GenerateLayout();
            //#endregion

            #region 设置表头
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];


                tb.Cells[0, 0].TextString = "Items";
                tb.Cells[0, 0].Contents[0].TextHeight = 3* scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                tb.Cells[0, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 0, 0, 1, 2));

                tb.Cells[0, 3].TextString = "unit";
                tb.Cells[0, 3].Contents[0].TextHeight = 3 * scale;
                tb.Cells[0, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 3].Contents[0].Rotation = 0;
                tb.Cells[0, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 0, 3, 1, 3));




                tb.Cells[0, 4].TextString = type.ToString() + "-" + typenum;
                tb.Cells[0, 4].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0, 4].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 4].Contents[0].Rotation = 0;
                tb.Cells[0, 4].Contents[0].TextStyleId = id;

                tb.Cells[1, 4].TextString = "L=" + (L * 0.001).ToString("0.000") + "M";
                tb.Cells[1, 4].Contents[0].TextHeight = 3 * scale;
                tb.Cells[1, 4].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 4].Contents[0].Rotation = 0;
                tb.Cells[1, 4].Contents[0].TextStyleId = id;


                tb.Cells[2, 0].TextString = "Qty.";
                tb.Cells[2, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[2, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[2, 0].Contents[0].Rotation = 0;
                tb.Cells[2, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 2, 0,2, 2));

                tb.Cells[2, 3].TextString = "Number";
                tb.Cells[2, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[2, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[2, 3].Contents[0].Rotation = 0;
                tb.Cells[2, 3].Contents[0].TextStyleId = id;
               

                tb.Cells[2, 4].TextString = totalNum.ToString();
                tb.Cells[2, 4].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[2, 4].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[2, 4].Contents[0].Rotation = 0;
                tb.Cells[2, 4].Contents[0].TextStyleId = id;

                tb.Cells[0, 5].TextString = "Total";
                tb.Cells[0, 5].Contents[0].TextHeight = 3 * scale;
                tb.Cells[0, 5].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 5].Contents[0].Rotation = 0;
                tb.Cells[0, 5].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 0, 5, 1, 6));

                tb.Cells[2, 5].TextString = (totalNum).ToString();
                tb.Cells[2, 5].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[2, 5].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[2, 5].Contents[0].Rotation = 0;
                tb.Cells[2, 5].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 2, 5, 2, 6));
                double totalWeight = 0;
                for (int i = 0; i < dic.Count; i++)
                {

                    KeyValuePair<eDB, List<RebarBase>> pr = new KeyValuePair<eDB, List<RebarBase>>();
                    pr = dic.ElementAt(i);

                    //// 类型
                    //tb.Cells[i+3, 1].TextString = pr.Key.ToString();
                    //tb.Cells[i+3, 1].Contents[0].TextHeight = 2 * scale;
                    //tb.Cells[i+3, 1].Alignment = CellAlignment.MiddleCenter;
                    //tb.Cells[i+3, 1].Contents[0].Rotation = 0;
                    //tb.Cells[i+3, 1].Contents[0].TextStyleId = id;
                             
                    // 单位  i+3
                    tb.Cells[i+3, 2].TextString = pr.Key.ToString();
                    tb.Cells[i+3, 2].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[i+3, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[i+3, 2].Contents[0].Rotation = 0;
                    tb.Cells[i+3, 2].Contents[0].TextStyleId = id;

                    // 数量
                    double weight = 0;
                    foreach (RebarBase info in pr.Value)
                    {
                        weight += info.TotalWeight * totalNum;
                    }

                    tb.Cells[i+3, 4].TextString = (weight).ToString("0.000")/* string.Format("{0:N3}", weight)*/;
                    tb.Cells[i+3, 4].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[i+3, 4].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[i+3, 4].Contents[0].Rotation = 0;
                    tb.Cells[i+3, 4].Contents[0].TextStyleId = id;

                    tb.Cells[i+3, 5].TextString = (weight).ToString("0.000")/*string.Format("{0:N3}", totalWeight)*/;
                    tb.Cells[i+3, 5].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[i+3, 5].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[i+3, 5].Contents[0].Rotation = 0;
                    tb.Cells[i+3, 5].Contents[0].TextStyleId = id;
                    // 总数
                    totalWeight += weight;


                    // 总数
              
                }



                tb.Cells[3, 0].TextString = "Material";
                tb.Cells[3, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[3, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[3, 0].Contents[0].Rotation = 0;
                tb.Cells[3, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 3, 0, 3+dic.Count-1, 0));

                tb.Cells[3, 1].TextString = "Bars";
                tb.Cells[3, 1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[3, 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[3, 1].Contents[0].Rotation = 0;
                tb.Cells[3, 1].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 3, 1, 3 + dic.Count - 1, 1));

             

                tb.Cells[3, 3].TextString = "kg";
                tb.Cells[3, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[3, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[3, 3].Contents[0].Rotation = 0;
                tb.Cells[3, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 3, 3, 3 + dic.Count - 1, 3));

                tb.Cells[3, 6].TextString = (totalWeight).ToString("0.000");
                tb.Cells[3, 6].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[3, 6].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[3, 6].Contents[0].Rotation = 0;
                tb.Cells[3, 6].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 3, 6, 3 + dic.Count - 1, 6));

                for (int i = 0; i < row; ++i)
                {
                    tb.Rows[i].Height = 8 * scale;
                }
                for (int i = 0; i < col; ++i)
                {
                    if(i>3&&i<=col-1)
                        tb.Columns[i].Width = 20 * scale;
                    else
                       tb.Columns[i].Width = 16 * scale;
                }

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                tr.Commit();
                Extents3d ex3d = new Extents3d(tb.Bounds.Value.MinPoint.Convert3D(), tb.Bounds.Value.MaxPoint.Convert3D());
                ext = ex3d.Convert2D();
                #endregion


                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

            }


        }

        /// <summary>
        /// 批量汇总
        /// </summary>
        /// <param name="db"></param>
        /// <param name="rets"></param>
        /// <param name="LLst"></param>
        /// <param name="startPoint"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <param name="title"></param>
        /// <param name="pierDiv"></param>
        /// <param name="pagnum"></param>
        /// <param name="tkPath"></param>
        public static void DrawListMergeTable(Database db, List<MemberBase> rets,List<int> LLst,
Point3d startPoint, string txtStyle, double scale, string title = "MAINLINE",string pierDiv="", int pagnum = 2, string tkPath = "")
        {
            Extents2d ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
            Table tb = new Table();

            List<Dictionary<eDB, List<RebarBase>>> dicList = new List<Dictionary<eDB, List<RebarBase>>>();
            foreach (MemberBase ret in rets)
            {
                if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
                {
                    throw new Exception("数据异常");
                }

                Dictionary<eDB, List<RebarBase>> dic = new Dictionary<eDB, List<RebarBase>>();      // 统计合并项

                #region 统计合并数据
                foreach (RebarBase item in ret.RebarList)
                {
                    if (dic.Count == 0)
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                    else
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        dic.TryGetValue(item.Diameter, out items);
                        if (items == null || items.Count == 0)
                        {
                            items = new List<RebarBase>();
                        }
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                }
                dicList.Add(dic);

                #endregion
            }




            //#region 设置表格长宽

            int row = 3 + dicList[0].Count+1;

            int col = 6 + rets.Count; 

            tb.SetSize(row, col);
            tb.Position = startPoint;
            tb.GenerateLayout();
            //#endregion

            #region 设置表头
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];


                tb.Cells[0, 0].TextString = "Items";
                tb.Cells[0, 0].Contents[0].TextHeight = 3 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                tb.Cells[0, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 0, 0, 1, 2));

                tb.Cells[0, 3].TextString = "unit";
                tb.Cells[0, 3].Contents[0].TextHeight = 3 * scale;
                tb.Cells[0, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 3].Contents[0].Rotation = 0;
                tb.Cells[0, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 0, 3, 1, 3));


                tb.Cells[2, 0].TextString = "Qty.";
                tb.Cells[2, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[2, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[2, 0].Contents[0].Rotation = 0;
                tb.Cells[2, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 2, 0, 2, 2));

                tb.Cells[2, 3].TextString = "Number";
                tb.Cells[2, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[2, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[2, 3].Contents[0].Rotation = 0;
                tb.Cells[2, 3].Contents[0].TextStyleId = id;


                tb.Cells[row-1, 1].TextString = "Concrete";
                tb.Cells[row-1, 1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[row-1, 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[row-1, 1].Contents[0].Rotation = 0;
                tb.Cells[row-1, 1].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, row - 1, 1, row - 1, 2));

                tb.Cells[row - 1, 3].TextString = "m3";
                tb.Cells[row - 1, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[row - 1, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[row - 1, 3].Contents[0].Rotation = 0;
                tb.Cells[row - 1, 3].Contents[0].TextStyleId = id;

                tb.Cells[0, 4 + dicList.Count].TextString = "Total";
                tb.Cells[0, 4 + dicList.Count].Contents[0].TextHeight = 3 * scale;
                tb.Cells[0, 4 + dicList.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 4 + dicList.Count].Contents[0].Rotation = 0;
                tb.Cells[0, 4 + dicList.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 0, 4 + dicList.Count, 1, 5 + dicList.Count));


                double totalWeight = 0;
                double totalnum = 0;
                double totalvol= 0;
                Dictionary<eDB, List<RebarBase>> dic = dicList[0];
                //int count = dicList[0].Count;
                Dictionary<eDB, double> totalDic = new Dictionary<eDB, double>();
                for (int m = 0; m < dicList.Count; m++)
                {
                    tb.Cells[0, 4+m].TextString =rets[m].TypeName;
                    tb.Cells[0, 4+m].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, 4+m].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 4+m].Contents[0].Rotation = 0;
                    tb.Cells[0, 4+m].Contents[0].TextStyleId = id;

                    tb.Cells[1, 4+m].TextString = "L=" + (LLst[m] * 0.001).ToString("0.000") + "M";
                    tb.Cells[1, 4+m].Contents[0].TextHeight = 3 * scale;
                    tb.Cells[1, 4+m].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, 4+m].Contents[0].Rotation = 0;
                    tb.Cells[1, 4+m].Contents[0].TextStyleId = id;

                    tb.Cells[row-1, 4 + m].TextString = (rets[m].ConcreteVolumn  *rets[m].Count).ToString();
                    tb.Cells[row-1, 4 + m].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[row-1, 4 + m].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[row-1, 4 + m].Contents[0].Rotation = 0;
                    tb.Cells[row-1, 4 + m].Contents[0].TextStyleId = id;
                    totalvol += rets[m].ConcreteVolumn * rets[m].Count;

                    dic = dicList[m];
                    totalnum += rets[m].Count;
                    tb.Cells[2, 4+m].TextString = (rets[m].Count).ToString();
                    tb.Cells[2, 4+m].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[2, 4+m].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[2, 4+m].Contents[0].Rotation = 0;
                    tb.Cells[2, 4+m].Contents[0].TextStyleId = id;

                    for (int i = 0; i < dic.Count; i++)
                    {
                        KeyValuePair<eDB, List<RebarBase>> pr = new KeyValuePair<eDB, List<RebarBase>>();
                        pr = dic.ElementAt(i);
                        if (m == 0)
                        {
                            // 单位  i+3
                            tb.Cells[i + 3, 2].TextString = pr.Key.ToString();
                            tb.Cells[i + 3, 2].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[i + 3, 2].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[i + 3, 2].Contents[0].Rotation = 0;
                            tb.Cells[i + 3, 2].Contents[0].TextStyleId = id;
                        }


                        // 数量
                        double weight = 0;
                        foreach (RebarBase info in pr.Value)
                        {
                            weight += info.TotalWeight * rets[m].Count;
                        }

                        tb.Cells[i + 3, 4 + m].TextString = (weight).ToString("0.000")/* string.Format("{0:N3}", weight)*/;
                        tb.Cells[i + 3, 4 + m].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i + 3, 4 + m].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i + 3, 4 + m].Contents[0].Rotation = 0;
                        tb.Cells[i + 3, 4 + m].Contents[0].TextStyleId = id;

                      
                        // 总数
                        totalWeight += weight;
                        if (totalDic.Keys.Contains(pr.Key))
                        {
                            double val = totalDic[pr.Key];
                            val += weight;
                            totalDic.Remove(pr.Key);

                            totalDic.Add(pr.Key, val);
                        }
                        else
                        {
                            totalDic.Add(pr.Key, weight);
                        }
                        // 总数

                    }
                }
                for (int i = 0; i < totalDic.Count; i++)
                {
                    tb.Cells[i + 3, 4 + dicList.Count].TextString = (totalDic[totalDic.Keys.ToList()[i]]).ToString("0.000")/*string.Format("{0:N3}", totalWeight)*/;
                    tb.Cells[i + 3, 4 + dicList.Count].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[i + 3, 4 + dicList.Count].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[i + 3, 4 + dicList.Count].Contents[0].Rotation = 0;
                    tb.Cells[i + 3, 4 + dicList.Count].Contents[0].TextStyleId = id;
                }

                tb.Cells[2, 4 + dicList.Count].TextString = (totalnum).ToString();
                tb.Cells[2, 4 + dicList.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[2, 4 + dicList.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[2, 4 + dicList.Count].Contents[0].Rotation = 0;
                tb.Cells[2, 4 + dicList.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 2, 4 + dicList.Count, 2, 5 + dicList.Count));

                tb.Cells[row-1, 4 + dicList.Count].TextString = (totalvol).ToString();
                tb.Cells[row-1, 4 + dicList.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[row-1, 4 + dicList.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[row-1, 4 + dicList.Count].Contents[0].Rotation = 0;
                tb.Cells[row-1, 4 + dicList.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, row-1, 4 + dicList.Count, row - 1, 5 + dicList.Count));

                tb.Cells[3, 0].TextString = "Material";
                tb.Cells[3, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[3, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[3, 0].Contents[0].Rotation = 0;
                tb.Cells[3, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 3, 0, 3 + dic.Count - 1, 0));

                tb.Cells[3, 1].TextString = "Bars";
                tb.Cells[3, 1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[3, 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[3, 1].Contents[0].Rotation = 0;
                tb.Cells[3, 1].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 3, 1, 3 + dic.Count - 1, 1));



                tb.Cells[3, 3].TextString = "kg";
                tb.Cells[3, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[3, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[3, 3].Contents[0].Rotation = 0;
                tb.Cells[3, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 3, 3, 3 + dic.Count - 1, 3));

                tb.Cells[3, 5 + dicList.Count].TextString = (totalWeight).ToString("0.000");
                tb.Cells[3, 5 + dicList.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[3, 5 + dicList.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[3, 5 + dicList.Count].Contents[0].Rotation = 0;
                tb.Cells[3, 5 + dicList.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 3, 5 + dicList.Count, 3 + dic.Count - 1, 5 + dicList.Count));

                for (int i = 0; i < row; ++i)
                {
                    tb.Rows[i].Height = 8 * scale;
                }
                for (int i = 0; i < col; ++i)
                {
                    if (i > 3 && i <= col - 1)
                        tb.Columns[i].Width = 20 * scale;
                    else
                        tb.Columns[i].Width = 16 * scale;
                }

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                tr.Commit();
                Extents3d ex3d = new Extents3d(tb.Bounds.Value.MinPoint.Convert3D(), tb.Bounds.Value.MaxPoint.Convert3D());
                ext = ex3d.Convert2D();
                #endregion


                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion


                string str1 = string.Format("QUANTITIES OF PRECAST RC DECK PANELS FOR {0} OF {1}",pierDiv,title);
                string str2 = "";
                TextPloter.PrintScaleDoubleSideText(db, startPoint.Convert2D(tb.Width / 2, 4 * scale), 3, str1, str2, ref ext, scale, Extensions.curFont);

                Common.CreateLayoutNew(db, "预制板钢筋", ext, scale, 1, -1, 0, false, tkPath);
            }


        }
        #endregion
    }
}
